﻿using Microsoft.AspNetCore.Mvc.Filters;
using RAP.Web.Libary.Controller.Attributes;
using System.Threading.Tasks;

namespace RAP.Web.Libary.Controller.Filters
{
  /// <summary>
  /// 处理查询参数的Filter，包括UserSession的初始化
  /// </summary>
  public class QueryParamsFilter : IAsyncActionFilter
  {
    /// <summary>
    /// 
    /// </summary>
    /// <param name="context"></param>
    /// <param name="next"></param>
    /// <returns></returns>
    public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
    {
      var result = await QueryParamsAttribute.ProcessAttributes(context);
      if (result)
      {
        await next();
      }
      else
      {
        context.Result = await (context.Controller as IWebController).ErrorContent("参数错误！");
      }
    }
  }
}
